//
//  HWlibaobagtankuanView.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/5/28.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWlibaobagtankuanView.h"

@interface HWlibaobagtankuanView()
@property(strong,nonatomic) UIView *grayView;
//@property(strong,nonatomic) UIView *whiteView;
@property(strong,nonatomic) UIView *fenxiangView;
@property(strong,nonatomic) UILabel *miahsulabel;


@end



@implementation HWlibaobagtankuanView






- (instancetype)initWithFrame:(CGRect)frame  {
    
    if (self  = [super initWithFrame:frame]) {
        // 添加灰色背景
        [self addgrayView];
        
        [self setupUI];
        
        
    }
    return  self;
    
}



//  设置UI
- (void)setupUI {
    
    self.fenxiangView = [[UIView alloc]initWithFrame:CGRectMake(20, (kScreenH-120)/2, kScreenW -40, 120)];
    self.fenxiangView.backgroundColor =  [UIColor whiteColor];
    self.fenxiangView.layer.cornerRadius = 14;
    self.fenxiangView.layer.masksToBounds = YES;
    [self addSubview:self.fenxiangView];
    
    UILabel *libaomafenxianlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, kScreenW-40, 20)];
    
    libaomafenxianlabel.text = @"礼包码";
    libaomafenxianlabel.font = [UIFont systemFontOfSize:16];
    libaomafenxianlabel.textColor = RGB(51, 51, 51);
    libaomafenxianlabel.textAlignment =  NSTextAlignmentCenter;
    [self.fenxiangView  addSubview:libaomafenxianlabel];
    
    
    
    
    
    
    UILabel *fenxianlabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, kScreenW-40-10, 20)];
    
    fenxianlabel.text = @"";
    fenxianlabel.font = [UIFont systemFontOfSize:16];
    fenxianlabel.textColor = RGB(51, 51, 51);
    fenxianlabel.textAlignment =  NSTextAlignmentLeft;
    self.miahsulabel = fenxianlabel;
    
    [self.fenxiangView  addSubview:fenxianlabel];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake((self.fenxiangView.width -150)/2, 120-35-10, 150, 35);
    NSString *fuzhi = [HWjianzhiduiObject keylocalization:@"复制"];
    [button setTitle:fuzhi forState:UIControlStateNormal];
    [button setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(quiabuttontap) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    button.backgroundColor = RGB(229, 109, 54);
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    [self.fenxiangView addSubview:button];
    
    
    
    
    
}

// 确定复制
- (void)quiabuttontap {
    
    
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string =  self.zifuchuanStr;
    [MBProgressHUD showError:@"复制成功"];
    [self removeFromSuperview];
    
    
    
    
    
}

- (void)relayoutTheChildControls {
//    // self.whiteView.backgroundColor = [UIColor redColor];
//    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 120);
//    self.grayView.frame = CGRectMake(0, self.whibackvieY+120, kScreenW, kScreenH-self.whibackvieY-118+10);
//

    
}






// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,0, kScreenW, kScreenH);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}

- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}


- (void)setZifuchuanStr:(NSString *)zifuchuanStr {
    
      _zifuchuanStr = zifuchuanStr;
    
    self.miahsulabel.text = zifuchuanStr;
    
    
    
    
    
}


//点击buton 按钮






//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//
//    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
//
//        return NO;
//    }else if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableView"]) {
//
//
//        return NO;
//    }
//    return YES;
//
//
//}



@end







#pragma mark ----- 以前代码

//#import "HWlibaobagtankuanView.h"
//
//@interface HWlibaobagtankuanView()
//@property(strong,nonatomic) UIView *grayView;
////@property(strong,nonatomic) UIView *whiteView;
//@property(strong,nonatomic) UIView *fenxiangView;
//@property(strong,nonatomic) UILabel *miahsulabel;
//
//
//@end
//
//
//
//@implementation HWlibaobagtankuanView
//
//
//
//
//
//
//- (instancetype)initWithFrame:(CGRect)frame  {
//
//    if (self  = [super initWithFrame:frame]) {
//        // 添加灰色背景
//        [self addgrayView];
//
//        [self setupUI];
//
//
//    }
//    return  self;
//
//}
//
////  设置UI
//- (void)setupUI {
//
//    self.fenxiangView = [[UIView alloc]initWithFrame:CGRectMake(20, (kScreenH-120)/2, kScreenW -40, 120)];
//    self.fenxiangView.backgroundColor =  [UIColor whiteColor];
//    self.fenxiangView.layer.cornerRadius = 14;
//    self.fenxiangView.layer.masksToBounds = YES;
//    [self addSubview:self.fenxiangView];
//
//
//
//
//    UILabel *fenxianlabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, kScreenW-40-10, 20)];
//
//    fenxianlabel.text = @"";
//    fenxianlabel.font = [UIFont systemFontOfSize:16];
//    fenxianlabel.textColor = RGB(51, 51, 51);
//    fenxianlabel.textAlignment =  NSTextAlignmentLeft;
//    self.miahsulabel = fenxianlabel;
//
//    [self.fenxiangView  addSubview:fenxianlabel];
//
//
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake( self.fenxiangView.width -90, 120-35, 90, 35);
//
//    NSString *fuzhi = [HWjianzhiduiObject keylocalization:@"复制"];
//
//
//    [button setTitle:fuzhi forState:UIControlStateNormal];
//    [button setTitleColor:RGB(51, 51, 51) forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(quiabuttontap) forControlEvents:UIControlEventTouchUpInside];
//    button.titleLabel.font = [UIFont systemFontOfSize:16];
//    [self.fenxiangView addSubview:button];
//
//
//
//
//
//}
//
//// 确定复制
//- (void)quiabuttontap {
//
//
//    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
//    pasteboard.string =  self.zifuchuanStr;
//    [MBProgressHUD showError:@"复制成功"];
//    [self removeFromSuperview];
//
//
//
//
//
//}
//
//- (void)relayoutTheChildControls {
////    // self.whiteView.backgroundColor = [UIColor redColor];
////    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 120);
////    self.grayView.frame = CGRectMake(0, self.whibackvieY+120, kScreenW, kScreenH-self.whibackvieY-118+10);
////
//
//
//}
//
//
//
//
//
//
//// 添加灰色View
//-(void)addgrayView {
//
//    self.grayView = [[UIView alloc]init];
//    self.grayView.frame  = CGRectMake(0,0, kScreenW, kScreenH);
//
//    self.grayView.backgroundColor =  RGB(51, 51, 51);
//    self.grayView.alpha = 0.6;
//    [self addSubview:self.grayView];
//
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
//    //  tap.delegate = self;
//    [self.grayView addGestureRecognizer:tap];
//
//
//
//
//}
//
//- (void)tapView:(UITapGestureRecognizer *)touch {
//
//    [touch.view.superview removeFromSuperview];
//    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
//
//
//}
//
//
//- (void)setZifuchuanStr:(NSString *)zifuchuanStr {
//
//      _zifuchuanStr = zifuchuanStr;
//
//    self.miahsulabel.text = zifuchuanStr;
//
//
//
//
//
//}
//
//
////点击buton 按钮
//
//
//
//
//
//
////-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
////
////    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
////
////        return NO;
////    }else if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableView"]) {
////
////
////        return NO;
////    }
////    return YES;
////
////
////}
//
//
//
//@end
//
